﻿namespace CodingExercises._11_20;

public class DiscountCodeGenerator
{
    // 生成随机折扣码
    private readonly IRandom _random;
    private const string Characters = "QWERTYUIOPASDFGHJKLZXCVBNM";

    public DiscountCodeGenerator(IRandom random)
    {
        _random = random;
    }

    public string GenerateDiscountCode(int length)
    {
        char[] code = new char[length];
        for (int i = 0; i < length; i++)
        {
            int index = _random.Next(0, Characters.Length);
            code[i] = Characters[index];
        }

        return new string(code);
    }
}

public interface IRandom
{
    int Next(int minValue, int maxValue);
}